﻿using Hidistro.UI.Common.Controls;
using JSShop.Model;
using Juse.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class CategoryBrandMap : AscxTemplatedWebControl
    {
        private Repeater PList;
        private int len;
        private CategoryBrowser CategoryBrowser = new CategoryBrowser();
        protected override void AttachChildControls()
        {
            this.PList = (Repeater)this.FindControl("PList");
            if (this.PList == null)
                return;
            this.PList.ItemDataBound += PList_ItemDataBound;
            IList<Hishop_Categories> list = CategoryBrowser.GetSubCategories(0, 0);
            len = list.Count;
            this.PList.DataSource = list;
            this.PList.DataBind();
        }

        private void PList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                len--;
                if (len == 0)
                {
                    HtmlGenericControl li = (HtmlGenericControl)e.Item.FindControl("li");
                    li.Attributes.Add("class", "goods");
                }
                Hishop_Categories ci = (Hishop_Categories)e.Item.DataItem;
                IList<Hishop_Categories> list = CategoryBrowser.GetSubCategories(ci.CategoryId, 0);
                Repeater top3 = (Repeater)e.Item.FindControl("top3");
                top3.DataSource = list.Take(3);
                top3.DataBind();
                Repeater FList = (Repeater)e.Item.FindControl("FList");
                FList.DataSource = list;
                FList.DataBind();
                Repeater BList = (Repeater)e.Item.FindControl("BList");
                BList.DataSource = CategoryBrowser.GetBrandList(ci.Path, 8);
                BList.DataBind();
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/ascx/tags/Common_GoodsList/CategoryBrandMap.ascx";
            }
            base.OnInit(e);
        }
    }
}
